package cn.edu.tyu.util;

import java.sql.*;

/**
 * MySql数据库实用类
 * @author  Shangxin
 * @version 1.0
 */
public class DbUtil {
    public static void main(String[] args) {
        DbUtil dbUtil = new DbUtil();
        Connection conn = DbUtil.getConnection();
        System.out.println(conn);
    }

    public static Connection getConnection() {
        Connection conn = null;
        String url = "jdbc:mysql://localhost:3306/financedb";
        try {
            conn = DriverManager.getConnection(url, "root", "ROOT");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }

    public static void backConn(Connection conn, PreparedStatement ps, ResultSet rs){
        if (rs!=null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (ps!=null) {
            try {
                ps.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (conn!=null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

}